$(function () {

    $.post($.webPath() + '/base/sjzdsy/get_sjzdz', {'bm': 'cd'}, function (cddata) {
        $.post($.webPath() + '/base/sjzdsy/get_sjzdz', {'bm': 'jzfs'}, function (data) {
            lldmxGrid($.webPath() + '/kcgl/nbll/nbll_lldmx?lldId=' + $("[name='lld.id']").val() || '', cddata, data);
        })
    });

})

function lldmxGrid(href, cdOptions, fsOptions) {
    $("#lld_mx_table").edatagrid({
        url: href,
        fitColumns: false,
        singleSelect: true,
        fit: true,
        checkOnSelect: false,
        selectOnCheck: false,
        showFooter: true,
        rownumbers: true,
        toolbar: "#lld_lldmx_toolbar",
        columns: [
            [
                {field: 'id', title: 'ID', hidden: true, rowspan: 2},
                {field: 'wzgg.code', title: '物资编码', align: 'center', width: 100, rowspan: 2},
                {field: 'wzgg.name', title: '物资名称', align: 'center', width: 100, rowspan: 2},
                {field: 'wzgg.ggxh', title: '规格型号', align: 'center', width: 100, rowspan: 2},
                {field: 'wzgg.dw', title: '单位', align: 'center', width: 70, rowspan: 2},
                {field: 'kh.khbm', title: '卡号', align: 'center', width: 120, rowspan: 2},
                {field: 'cgdh', title: '采购单号', align: 'center', width: 120, rowspan: 2},
                {field: 'cd.z', title: '产地', align: 'center', width: 70, rowspan: 2},
                {field: 'chd', title: '长度', width: 70, rowspan: 2},
                {field: 'jz', title: '件重', width: 70, rowspan: 2},
                {field: 'jzfs.z', title: '计重方式', align: 'center', width: 70, rowspan: 2},
                {field: 'kddj', title: '单价(不含税)', align: 'right', formatter: function (value) {
                    var sl = formatJe(value, ",");
                    return sl;
                }, width: 100, rowspan: 2},
                {title: '开单', colspan: 3},
                {title: '发料', colspan: 3},
                {field: 'llbz', title: '备注', align: 'center', width: 100, rowspan: 2}
            ],
            [
                {field: 'kdjs', title: '件数', align: 'right', formatter: function (value) {
                    var sl = formatSl(value, ",");
                    return sl;
                }, width: 70},
                {field: 'kdsl', title: '数量', align: 'right', formatter: function (value) {
                    var sl = formatSl(value, ",");
                    return sl;
                }, width: 100},
                {field: 'kdje', title: '金额(不含税)', width: 100, align: 'right',
                    formatter: function (value) {
                        var sl = formatJe(value, ",");
                        return sl;
                    }
                },
                {field: 'fljs', title: '件数', align: 'right', formatter: function (value) {
                    var sl = formatSl(value, ",");
                    return sl;
                }, width: 70},
                {field: 'flsl', title: '数量', align: 'right', formatter: function (value) {
                    var sl = formatSl(value, ",");
                    return sl;
                }, width: 100},
                {field: 'flje', title: '金额(不含税)', width: 100, align: 'right',
                    formatter: function (value) {
                        var sl = formatJe(value, ",");
                        return sl;
                    }
                }
            ]
        ],
        onLoadSuccess: function () {
            $(".datagrid-htable .datagrid-cell").css('text-align', 'center');
        }
    })
}

//tab面板的切换
$('#lldmxForm').tabs({
    border: false,
    onSelect: function (title) {
        if (title == "领料打印") {
            $.ajax({
                type: "POST",
                url: $.webPath() + '/kcgl/nbll/nbll_print_detail?lldId=' + $("[name='lld.id']").val(),
                dataType: "html",
                beforeSend: function () {
                    $.messager.progress();
                },
                success: function (data) {
                    $.messager.progress("close");
                    $('#nbll_content_id').html(data);
                }
            });
        }
    }
});

function nbllPrintPreview() {
    var LODOP = getLodop(document.getElementById('LODOP_OB_NBLL'), document.getElementById('LODOP_EM_NBLL'));
    LODOP.SET_PRINT_STYLEA(0, "NotOnlyHighPrecision", true);
    LODOP.PRINT_INIT("预览转库单");

    var strBodyStyle = "<style  type=\"text/css\">" +
        ".textcon{padding:8px;}" +
        ".input-tian{border-top:0 none;border-left:0 none;border-right:0 none;border-bottom: 1px solid black;height:22px;line-height:22px;width:100%;font-weight: bold;}" +
        " select{display:none}" +
        ".tb{width:auto;border-collapse:collapse;border-spacing:0;}" +
        ".tb th{padding:2px 2px 2px 12px;font-size:12px;font-weight:normal;text-align: right;}" +
        ".tb td{padding:2px;font-size:12px;}" +
        ".tb caption{ font-size:24px;height:60px;line-height:20px;}" +
        ".intb{width: 100%;}" +
        ".intb,.intb th,.intb td{border:1px solid black;}" +
        "</style>";
    var strFormHtmltops = strBodyStyle + "<div class='textcon'>" + document.getElementById("nbll_print_id").innerHTML + "</div>";
    var strFormHtmlbodys = strBodyStyle + "<div class='textcon'>" + document.getElementById("nbll_content_id").innerHTML + "</div>";
    var strFormHtmlBottoms = strBodyStyle + "<div class='textcon'>" + document.getElementById("nbll_detail_id").innerHTML + "</div>";

    LODOP.ADD_PRINT_TABLE(140, "1.5%", "90%", 350, strFormHtmlbodys);
    LODOP.SET_PRINT_STYLEA(0, "Vorient", 3);
    LODOP.ADD_PRINT_HTM(20, "1.5%", "90%", 145, strFormHtmltops);
    LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
    LODOP.SET_PRINT_STYLEA(0, "LinkedItem", 1);
    LODOP.ADD_PRINT_HTM(495, "1.5%", "90%", 200, strFormHtmlBottoms);
    LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
    LODOP.SET_PRINT_STYLEA(0, "LinkedItem", 1);
    LODOP.ADD_PRINT_TEXT(5, "80%", 135, 20, "总页号：第#页/共&页");
    LODOP.SET_PRINT_STYLEA(0, "ItemType", 2);
    LODOP.SET_PRINT_STYLEA(0, "Horient", 1);

    LODOP.PREVIEW();


}




